package api

import (
	"fmt"
	blogService "yunj/app/service/client"
	"yunj/pkg/yunj/core/response"

	"github.com/gin-gonic/gin"
)

type Article struct {
	Controller
}

func (ctrl *Article) List(c *gin.Context) {
	// 接收参数，绑定JSON数据到结构体
	var params blogService.ArticlePageListParams
	if err := c.ShouldBindJSON(&params); err != nil {
		response.Fail(c, fmt.Sprintf("参数错误！%v", err))
		return
	}
	// 验证数据
	params.InitValidator(&params)
	if err := params.Check(); err != nil {
		response.Fail(c, err.Error())
		return
	}
	// 获取分页数据
	data := blogService.Article.PageList(params)
	// fmt.Printf("qqqqq|%v\r\n", data)
	response.Success(c, data)
}
